<?php
include 'test_header.php' ;

class test_class_db_obj_problem extends UnitTestCase{

	function setUp(){
		$db = db_connect();
		$sql = "
CREATE TABLE IF NOT EXISTS `problem` (
  `problem_no` bigint(20) NOT NULL DEFAULT '0',
  `title` varchar(256) DEFAULT NULL,
  `content` text,
  `input` varchar(1024) DEFAULT NULL,
  `output` varchar(2048) DEFAULT NULL,
  `sample_input` text,
  `sample_output` text,
  `tip` text,
  `source` varchar(1024) DEFAULT NULL,
  `time_limit` varchar(16) DEFAULT '1000',
  `mem_limit` varchar(16) DEFAULT '65536',
  `best_user` varchar(256) DEFAULT NULL,
  `submit_count` bigint(20) DEFAULT NULL,
  `ac_count` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`problem_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
";
	
		$db->query( $sql );
	}

	function tearDown(){
		$db = db_connect();
		$sql = "DROP TABLE `problem`" ;
		$db->query( $sql );
	}


	function test_insert_new_problem_into_database_and_load_it(){

		$rand_no = rand() ;
		$db = db_connect() ;
		$request = array( 'problem_no'=>$rand_no , 'title'=>'a+b' 
			, 'content'=>'a+b?' , 'input'=>'a and b' 
			, 'output'=>'a+b=?' , 'tip'=>'1+1=2' 
			, 'sample_input'=>'123' , 'sample_output'=>'123' 
			, 'source'=>'me' , 'time_limit'=>'123' 
		        , 'mem_limit'=>'1024' , 'best_user'=>'me' );
		//添加新题目进数据库
		$prob = new db_obj_problem( $db );
		foreach( $request as $k => $v ){
			
			$prob->set( $k , $v ) ;
		
		}
		$this->assertTrue( $prob->save() );

		$prob_1 = new db_obj_problem( $db );
		$this->assertTrue( $prob_1->load( 'problem_no' , $rand_no ) ) ;
		
		foreach( $request as $k => $v ){
			
			$this->assertEqual( $prob_1->get($k),$v );
		
		}
			
	}



	
}
$test = new test_class_db_obj_problem();
$test->run( new HtmlReporter() );


